package cn.zymall.dict.controller;

import cn.zymall.common.controller.crud.BaseController;
import cn.zymall.common.model.SysDictItem;
import cn.zymall.common.utils.id.IDUtil;
import cn.zymall.dict.service.DictItemService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: DictItemController
 * @Description: TODO
 * @author: 欧泽昌
 * @date: 2020/8/21 23:34
 * @version: V1.0
 */
@RestController
@RequestMapping("dictItem")
public class DictItemController extends BaseController<DictItemService, SysDictItem> {
	@Autowired
	DictItemService dictItemService;
	@RequestMapping("queryAll")
	public List<SysDictItem> queryAll(SysDictItem sysDictItem){
		return dictItemService.queryAll(sysDictItem);
	}

	@PostMapping("batchUpdate")
	public int batchUpdate(@RequestBody Map map){
		System.out.println(map);
		List<SysDictItem> list=null;
		for (Object obj:map.values()) {
			list = JSONObject.parseArray(obj.toString(), SysDictItem.class);
		}
		return dictItemService.batchUpdate(list);
	}

	@Override
	public boolean insert(@RequestBody SysDictItem bean) {
		System.out.println(bean);
		bean.setId(IDUtil.generate8BitUUID());
		bean.setStatus(1);
		return super.insert(bean);
	}

	@Override
	public boolean update(@RequestBody SysDictItem bean) {
		System.out.println(bean);
		return super.update(bean);
	}

	@GetMapping("queryName")
	public List<SysDictItem> queryName(String name){
		return this.dictItemService.queryName(name);
	}
}
